<!DOCTYPE html>
<!--suppress ALL-->
<html lang="zh" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <title>主页</title>
    <link rel="stylesheet" th:href="@{/bootstrap/css/bootstrap.css}">
    <script th:src="@{/jquery/jquery-3.5.1.min.js}"></script>
</head>
<body>
    <form class="form-inline" th:action="@{/goods/goodsList}" method="get">
        <input class="form-control" type="text" name="goodsName" placeholder="请输入商品名称" th:value="${goodsName}"> &nbsp;
        <select class="form-control" name="typeId">
            <option value="0">请选择</option>
            <option th:selected="${#strings.equals(typeId, type.typeid)}" th:each="type : ${goodsTypes}" th:value="${type.typeid}" th:text="${type.typename}"></option>
        </select> &nbsp;
        <input type="submit" class="btn btn-success" value="搜索">
        <input type="reset" class="btn btn-primary" value="重置">
    </form>
    <p>
        <a th:href="@{/order/orderList}" class="btn btn-default">查看订单</a>
    </p>
    <table class="table table-bordered table-responsive">
        <tr>
            <th>#</th>
            <th>商品名称</th>
            <th>商品类型</th>
            <th>商品数量</th>
            <th>操作</th>
        </tr>
        <tr th:each="goods : ${pageInfo.list}">
            <th><input type="checkbox" th:value="${goods.gid}"></th>
            <th th:text="${goods.gname}">iphone 4</th>
            <th th:text="${goods.typeName}" th:value="${goods.typeId}">手机</th>
            <th th:text="${goods.count}">100</th>
            <th><button type="button" th:onclick="|orders(${goods.gid})|" class="btn btn-warning">下单</button></th>
        </tr>
        <tfoot>
        <tr >
            <td colspan="5" align="center">
                <ul class="pagination">
                    <li><a th:href="@{/goods/goodsList(now=${pageInfo.prePage}, goodsName=${goodsName}, typeId=${typeId})}">上一页</a></li>
                    <li><a th:each="page : ${pageInfo.getNavigatepageNums()}" th:text="${page}" th:href="@{/goods/goodsList(now=${page}, goodsName=${goodsName}, typeId=${typeId})}">1</a></li>
                    <li><a th:href="@{/goods/goodsList(now=${pageInfo.nextPage}, goodsName=${goodsName}, typeId=${typeId})}">下一页</a></li>
                </ul>
            </td>
        </tr>

        </tfoot>
    </table>
    <


    <script th:src="@{/bootstrap/js/bootstrap.js}"></script>
    <script th:inline="javascript">
        function orders(gid) {
            let url = /*[[@{/goods/orders}]]*/;
            let params = "gid=" + gid;
            $.post(url, params, function (data) {
                if (data == "1") {
                    alert("下单成功");
                    window.location.href = /*[[@{/goods/goodsList(now=${pageInfo.getPageNum()}, goodsName=${goodsName}, typeId=${typeId})}]]*/
                } else {
                    alert("下单失败");
                }
            });
        }
    </script>
</body>
</html>